import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:geomancy/providers/system_provider.dart';
import 'package:geomancy/styles/index.dart';
import 'package:provider/provider.dart';

class PermissionReasonModal {
  static OverlayEntry? _overlayEntry;

  static cancel() {
    Future.delayed(const Duration(milliseconds: 500), () {
      _overlayEntry?.remove();
      _overlayEntry = null;
    });
  }


  static show(BuildContext context, String tips, {double? height}) async {
    OverlayState? overlayState = Overlay.of(context);

    _overlayEntry = OverlayEntry(builder: (BuildContext context) {
      final topSafe = context.read<SystemProvider>().getTopSafeHeight ?? 36.w;
      return Container(
        color: Colors.black38,
        alignment: Alignment.topCenter,
        padding: EdgeInsets.only(top: topSafe),
        child: Container(
          width: 650.w,
          height: height ?? 240.w,
          // padding: EdgeInsets.fromLTRB(32.w, 24.w, 32.w, 24.w),
          padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.w),
          decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(32.w))
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('权限使用说明', style: TextStyle(fontSize: 30.sp, color: ColorStyle.textColor, fontWeight: FontWeight.bold)),
              SizedBox(height: 12.w,),
              Text(tips, style: TextStyle(fontSize: 28.sp, color: ColorStyle.textColor),)
            ],
          ),
        ),
      );
    });
    overlayState.insert(_overlayEntry!);
  }
}
